package pl.extremme.robocode.utils;

/**
 * Represents a point in polar coordinate system. Please remember that
 * 0 degress is in the north, 90 degrees is in the east, 180 in the south and
 * 270 degrees in the west.
 *
 * @author XyC
 */
class PolarPoint {

    private double m_Distance;
    private double m_Angle;

    public PolarPoint() {
        this.m_Angle = 0;
        this.m_Distance = 0;
    }

    public PolarPoint(double p_Distance, double p_Angle) {
        this.m_Distance = p_Distance;
        this.m_Angle = p_Angle;
    }

    public double getAngle() {
        return this.m_Angle;
    }

    public double getDistance() {
        return this.m_Distance;
    }

    public void setAngle(double p_Angle) {
        if(p_Angle < 0) {
            throw new ArithmeticException("Angle has to be positive");
        }
        this.m_Angle = p_Angle;
    }

    public void setDistance(double p_Distance) {
        if(p_Distance < 0) {
            throw new ArithmeticException("Distance has to be positive");
        }
        this.m_Distance = p_Distance;
    }

    @Override
    public String toString() {
        return "(r, O) => (" + this.getDistance() + ", " + this.getAngle() + ")";
    }

    @Override
    public boolean equals(Object obj) {
        boolean ret = false;
        if(obj instanceof PolarPoint) {
            PolarPoint other = (PolarPoint)obj;
            if(other.getDistance() == this.getDistance() && other.getAngle() == this.getAngle()) { // TODO: Think of angles above 360 degrees
                ret = true;
            }
        }
        return ret;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 67 * hash + (int) (Double.doubleToLongBits(this.m_Distance) ^ (Double.doubleToLongBits(this.m_Distance) >>> 32));
        hash = 67 * hash + (int) (Double.doubleToLongBits(this.m_Angle) ^ (Double.doubleToLongBits(this.m_Angle) >>> 32));
        return hash;
    }

}
